<?php include "inc/conn.php"; ?>
<?php
	// 获取数据
	$username = $_POST['username'];
	$phone = $_POST['phone'];
	$email = $_POST['email'];
	$content = $_POST['content'];
	// 验证数据的有效
	if(strlen($username)<6 || strlen($username)>20){
		die("<script>alert('账号必须是6~20个字符');history.go(-1)</script>");
	}
	// 补齐数据
	$createtime = time();
	// 添加数据到数据库
	$sql = "insert into message(username,phone,email,content,createtime) ";
	$sql .= "values('{$username}','{$phone}','{$email}','{$content}','{$createtime}')";
	$res = mysqli_query($conn,$sql) or die("命令写错了2".$sql);
	if($res){
		die("<script>alert('提交成功!');location.href='message.php';</script>");
	}else{
		die("<script>alert('提交失败!');history.go(-1)</script>");
	}
?>